package com.webchat.aigc.service.transfunction;


import com.google.common.collect.Sets;
import com.webchat.aigc.service.UserService;
import com.webchat.common.helper.SessionHelper;
import com.webchat.domain.vo.response.UserBaseResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component
public class UserName2UserIdFunc extends AbstractTransFuncService<String, String> {


    @Autowired
    private UserService userService;

    private static final Set<String> CURRENT_USER =
            Sets.newHashSet("我", "wo");


    @Override
    public String trans(String parameter) {

        String contextUserId = SessionHelper.getContextUserId();
        if (CURRENT_USER.contains(parameter)) {
            return contextUserId;
        }
        UserBaseResponseVO userBaseResponseVO = userService.accountInfoByName(parameter);
        return userBaseResponseVO == null ? "" : userBaseResponseVO.getUserId();
    }
}
